package MercuryTour;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;

public class TestFindAFlightPage {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws BiffException 
	 */
	public static void main(String[] args) throws BiffException, IOException {
		
		//Define spreadsheets
		File file = new File ("c:/test.xls");
		Workbook workbook = Workbook.getWorkbook(file);
		Sheet logininfosheet = workbook.getSheet(2);
		Sheet findaflightinfosheet = workbook.getSheet(3);
		
		//Define arrays to store values read from spreadsheets 
		int sizeOfArray = logininfosheet.getColumns();
		String[] loginInfo = new String[sizeOfArray];
		
		int sizeOfFlightInfoSheet = findaflightinfosheet.getColumns();
		String[] flightInfo = new String[sizeOfFlightInfoSheet];
		
		for (int i=0; i< logininfosheet.getRows();i++)
		{
		WebDriver driver = new FirefoxDriver();
		String baseUrl = "http://newtours.demoaut.com/";
		driver.get(baseUrl);
		loginPage loginpage = PageFactory.initElements(driver, loginPage.class);
		
		for (int j=0; j<logininfosheet.getColumns();j++)
		{	
			
			loginInfo[j] = logininfosheet.getCell(j, i).getContents();
	
		}
		loginpage.loginTo(loginInfo);
		
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		
		FindAFlightPage findaflightpage = PageFactory.initElements(driver, FindAFlightPage.class);
		
			for(int l=0;l<findaflightinfosheet.getColumns();l++)
			{
				flightInfo[l] = findaflightinfosheet.getCell(l, i).getContents();
			}
			findaflightpage.assignValuesAsSelection(flightInfo);
			findaflightpage.clickContinueButton();
		
		driver.close();
		}

	}

}
